package com.android.questions.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import com.android.base.util.ActivityClickUtil;
import com.android.base.util.DisplayUtil;
import com.android.questions.R;
import com.android.questions.databinding.DialogUnlockAnswerBinding;

/**
 * FileName: DialogUnlockAnswer
 * Author: admin
 * Date: 2022/1/19 17:34
 * Description:
 */
public class DialogUnlockAnswer extends Dialog implements View.OnClickListener {

    private DialogUnlockAnswerBinding answerBinding;
    private final Activity activity;
    private OnClickLister clickLister;

    public DialogUnlockAnswer(Activity act) {
        super(act, R.style.dialog_loading);
        this.activity = act;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        answerBinding = DialogUnlockAnswerBinding.inflate(activity.getLayoutInflater());
        setContentView(answerBinding.getRoot());

        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = DisplayUtil.getScreenWidth(activity);
        lp.height = DisplayUtil.getScreenHeight(activity);
        getWindow().setAttributes(lp);

        getWindow().setWindowAnimations(R.style.dialog_answer_correct);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
        initLister();
    }

    private void initLister() {
        answerBinding.imgLockNo.setOnClickListener(this);
        answerBinding.imgLockYes.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (ActivityClickUtil.getInstance().isFastClick()) {
            //防止用户快速点击
            return;
        }
        dismiss();
        if (v.getId() == R.id.imgLockNo) {
            if (this.clickLister != null) {
                this.clickLister.unlock(false);
            }
        } else if (v.getId() == R.id.imgLockYes) {
            if (this.clickLister != null) {
                this.clickLister.unlock(true);
            }
        }
    }

    public DialogUnlockAnswer setOnClickLister(OnClickLister lister) {
        this.clickLister = lister;
        return this;
    }

    public interface OnClickLister {
        void unlock(boolean isUnlock);
    }
}
